package net.piggy.core.util;

import net.piggy.core.config.GatewayConfig;
import java.util.Properties;

public class GatewayConfigUtil {
    private GatewayConfigUtil(){}

    private static volatile GatewayConfig gatewayConfig;

    public static GatewayConfig getGatewayConfig() {
        try {
            if(gatewayConfig == null) {
                synchronized (GatewayConfigUtil.class) {
                    if(gatewayConfig ==null){
                        gatewayConfig = new GatewayConfig();
                        Properties prop = new Properties();
                        prop.load(GatewayConfigUtil.class.getClassLoader().getResourceAsStream("piggy.properties"));
                        gatewayConfig.setPort(Integer.parseInt(prop.getProperty("piggy.port")));
                        gatewayConfig.setHostName(prop.getProperty("piggy.host"));
                        gatewayConfig.setZookeeperAddress(prop.getProperty("piggy.registryAddress"));
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return gatewayConfig;
    }
}
